Skip to content

Conversation

@tuxes3
Copy link

@tuxes3 tuxes3 commented May 27, 2025

when trying to use symfony services in the event-sourcing migration it would have never used my custom migration factory.

this fix changes that.

@DanielBadura
Copy link
Member

Thanks for the PR!

Just to clarify and because I never used services in migrations and therefore never used this: Is this correct? When looking into the docs it seems they recommend using a decorator and a compiler pass to add these services. https://symfony.com/bundles/DoctrineMigrationsBundle/current/index.html#migration-dependencies

Maybe our config here is wrong and we should also decorate the base class 🤔

@robinlehrmann
Copy link
Contributor

@DanielBadura

When looking into the docs it seems they recommend using a decorator and a compiler pass to add these services.

Yes, this is actually what we did in our case. If you would also create a decorator and make it possible to inject services in the migrations, that would be great 👍

@tuxes3
Copy link
Author

tuxes3 commented May 28, 2025

@DanielBadura yes. The DependencyFactory service is using a default . Having the default does not allow decorating the service.

@DanielBadura
Copy link
Member

DanielBadura commented May 29, 2025

But that is only the fallback if no service is found in the container given. https://github.com/doctrine/migrations/blob/3.9.x/src/DependencyFactory.php#L435-L439

I assume that, when using with the doctrine-bundle and symfony, this fallback will not be used.

@tuxes3
Copy link
Author

tuxes3 commented Jun 2, 2025

@DanielBadura here you have an application which reproduce the mentioned error: https://github.com/tuxes3/event-sourcing-migration-factory-test-app

As you can see I have 2 migrations directories: migrations (for doctrine) and MigrationsEventSourcing (for event-sourcing). I also created a Migration Factory (src/MigrationFactory.php) which will set some value to some field. Running both migration result in that output:

/var/www $ php bin/console doctrine:m:m -n
[notice] Migrating up to DoctrineMigrations\Version20250602160109
^ "value"
/var/www $ php bin/console event:m:m -n
[notice] Migrating up to App\MigrationsEventSourcing\Version20250602110811
^ null

Please ask if you need anymore help to reproduce!

@DavidBadura
Copy link
Member

DavidBadura commented Jun 3, 2025

Hey, thanks for the PR and your time!

We can't simply use the doctrine.migrations.migrations_factory service. Our bundle can be used independently of DoctrineBundle or DoctrineMigrationBundle. And if the user hasn't installed the bundle, this service doesn't exist.

We might not need to change anything and wanted to discuss another option with you. Since we want to be independent of Doctrine Bundles for now, we've registered many things ourselves as services, such as some CLI commands and migration. However, you have the option to switch to the Doctrine Bundle system by activating the merge_orm_schema configuration.

https://event-sourcing-bundle.patchlevel.io/latest/configuration/#merge-orm-schema

What happens then is that we no longer register the Schema/Migration Service ourselves, but use everything from the Doctrine Bundle. This should also work for injecting the service. If you're already using DoctrineBundle, wouldn't it make sense to switch to their system? Then you can use all of Doctrine Bundle's features.

The name merge_orm_schema might not be the right one, but rather something like use_doctrine_bundle_schema_management. I've already opened a ticket for that: #260

@robinlehrmann
Copy link
Contributor

@DavidBadura Hi 👋 Thanks for your input. I will add merge_orm_schema to our config and will try it out.

We might not need to change anything and wanted to discuss another option with you. Since we want to be independent of Doctrine Bundles for now, we've registered many things ourselves as services, such as some CLI commands and migration. However, you have the option to switch to the Doctrine Bundle system by activating the merge_orm_schema configuration.

This is good to know. Maybe as a suggestion you can add this to your docs as a information/notice to let other developers know, why you have this migration system (If it's not already in there, maybe I wasn't able to find it 😄)

@DavidBadura
Copy link
Member

Yes, we will update the documentation and rename the option. Before we change that, I like to hear your feedback on whether this helped.

@DanielBadura
Copy link
Member

@robinlehrmann @tuxes3 did the option merge_orm_schema help you to resolve your issue?

@robinlehrmann
Copy link
Contributor

@DanielBadura We haven't got round to testing it yet. But I will let you know as soon as we know more.

@robinlehrmann
Copy link
Contributor

@DanielBadura @DavidBadura FYI. The activation of the setting merge_orm_schema worked as expected 👍 I think we can close this issue, thank you for the help!

@DanielBadura
Copy link
Member

Alright, great to hear. We will then work on the documentation part to be more clear what the options does. Will close this PR then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants